package com.itheima.tanhua.web;

import com.itheima.tanhua.service.CommentService;
import com.itheima.tanhuan.vo.mongo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("comments")
public class CommentController {

    @Autowired
    CommentService commentService;


    /**
     * 点赞评论
     * @param id 评论id
     * @return
     */
    @GetMapping("{id}/like")
    public Integer likeComment(@PathVariable("id")String id){
        return commentService.likeComment(id);
    }


    /**
     * 取消点赞评论
     * @param id 评论id
     * @return
     */
    @GetMapping("{id}/dislike")
    public Integer dislikeComment(@PathVariable("id")String id){
        return commentService.dislikeComment(id);
    }

    /**
     * 评论列表
     * @param movementId 动态编号
     * @param page 当前页数
     * @param pagesize 页尺度
     * @return
     */
    @GetMapping
    public ResponseEntity comments(String movementId,
                                  Integer page,
                                   Integer pagesize){

        PageResult pr=commentService.comments(movementId,page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 提交评论
     * @param
     * @param
     * @return
     */
    @PostMapping
    public ResponseEntity commmentsPost(@RequestBody Map<String,String> map){
        String movementId=map.get("movementId");
        String comment=map.get("comment");
       commentService.commentsPost(movementId,comment);
        return ResponseEntity.ok(null);
    }






}
